package com.zzt.aop.proxy;


//import org.springframework.cglib.proxy.Enhancer;

import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 * Description
 * User: panda
 * Date: 2025-03-30
 * Time: 16:00
 */
/*public class Main {
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
        HouseSubject houseSubject = new HouseProxy(target);
//        houseSubject.saleHouse();
        houseSubject.rentHouse();
    }
}*/

/*public class Main {
    public static void main(String[] args) {

        HouseSubject target = new RealHouseSubject();

        //JDK动态代理
        //JDK创建一个代理类
        HouseSubject houseProxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class}, new JDKInvocation(target));
        houseProxy.rentHouse();
    }
}*/

public class Main {
    public static void main(String[] args) {

        HouseSubject target = new RealHouseSubject();

        //Cglib动态代理
        //--add-opens java.base/java.lang=ALL-UNNAMED
        HouseSubject houseProxy = (HouseSubject) Enhancer.create(target.getClass(), new CGlibMethodInterceptor(target));
        houseProxy.rentHouse();
    }
}
